package com.qf.controller;

import com.netflix.appinfo.InstanceInfo;
import com.netflix.discovery.EurekaClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class OrderController {

    @Autowired
    EurekaClient client;

    @Autowired
    RestTemplate template;

    @RequestMapping("/query")
    public String query(){

        //获取 qf-goods 的实例对象
        InstanceInfo instanceInfo = client.getNextServerFromEureka("qf-goods", false);
        String url = instanceInfo.getHomePageUrl();
        System.out.println(url);

        //远程调用 商品模块 控制器
        //响应实体对象
        ResponseEntity<String> responseEntity = template.getForEntity(url + "query", String.class);

        String body = responseEntity.getBody();

        //返回结果
        return "查询订单 ----- " + body;

    }
}